package library.and.xps.com.step.util;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class DateUtil {

    /**
     * @return 返回今天00：00 的毫秒值
     */
    public static long getDateMilliseconds(Date d) {
        Date d1 = new Date(d.getYear(), d.getMonth(), d.getDate());
        return d1.getTime();
    }

    /**
     * @return 从今天00：00 的毫秒开始的date
     */
    public static Date getSuitDate() {
        Date d = new Date();
        return new Date(d.getYear(), d.getMonth(), d.getDate());
    }

    /**
     * 得到日期 MM-dd
     *
     * @param time 时间戳
     * @return String
     */
    public static String formatDateSimple(long time) {
        String date = new SimpleDateFormat("MM/dd").format(time);
        return date;
    }

    /**
     * 得到日期 MM月dd日
     *
     * @param time
     * @return String
     */
    public static String formatDateSimpleWord(long time) {
        String date = new SimpleDateFormat("MM月dd日").format(time);
        return date;
    }

    /**
     * 得到日期 yyyy-MM-dd
     *
     * @param time
     * @return String
     */
    public static String formatDate(long time) {
        String date = new SimpleDateFormat("yyyy/MM/dd").format(time);
        return date;
    }

    public static int getDayofWeek(Long TimeStamp) {
        Calendar c = Calendar.getInstance();
        c.setTimeInMillis(TimeStamp);
        if (c.get(Calendar.DAY_OF_WEEK) == 1) {
            return 7;
        } else {
            return c.get(Calendar.DAY_OF_WEEK) - 1;
        }
    }

    //去零
    public static String trimZero(String str) {
        int zeroIndexd = str.indexOf("0");
        if (zeroIndexd == 0) {
            str = str.replaceFirst("0", "");
        }
        return str;
    }

    /**
     * 修改 时间字符串的样式 from 2017-5-20 00:00 to 5月20日
     * */
   public static String retrofitDateString(String startTime) {
        try {
            int sInx = startTime.indexOf("-");
            int eInx = startTime.lastIndexOf(" ");
            return startTime.substring(sInx + 1, eInx).replace("-", "月") + "日";
        } catch (Exception e) {
            e.printStackTrace();
            return "";
        }
    }

}
